package com.melody.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.melody.entry.MusicComment;
import com.melody.service.MusicCommentService;
import com.melody.mapper.MusicCommentMapper;
import com.melody.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
* @author zxz
* @description 针对表【music_comment(歌曲评论表)】的数据库操作Service实现
* @createDate 2025-05-09 10:31:17
*/
@Service
public class MusicCommentServiceImpl extends ServiceImpl<MusicCommentMapper, MusicComment>
    implements MusicCommentService{

    @Autowired
    MusicCommentMapper musicCommentMapper ;
    public List<MusicComment> getCommentsByMusicId(Integer musicId) {
        QueryWrapper<MusicComment> queryWrapper = new QueryWrapper<>();
        //根据id查询评论
        queryWrapper.eq("music_id", musicId);
        List<MusicComment> musicCommentList = musicCommentMapper.selectList(queryWrapper);
        return musicCommentList;
    }

    public  MusicComment addCommentsByMusic(MusicComment musicComment) {
        Map<String, Object> userInfo = ThreadLocalUtil.get();
        Integer userId = (Integer) userInfo.get("userId"); // 获取用户ID
        musicComment.setUserId(userId);
        musicComment.setStatus(1);
        musicComment.setLikeCount(0);
        musicComment.setCommentCreateTime(LocalDateTime.now());
        save(musicComment);
        return musicComment;
    }
}




